package com.starnet.yarnmonitor.yarn.conf;

import lombok.Data;
import org.apache.hadoop.yarn.client.api.YarnClient;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(prefix = "my.hadoop.yarn")
@Data
@EnableConfigurationProperties(YarnConf.class)
public class YarnConf {
    private String host;
    private String port;

    @Bean
    public YarnClient myYARN() {
        org.apache.hadoop.conf.Configuration conf = new YarnConfiguration();
        conf.set("ipc.client.connect.max.retries","1");
        YarnClient yarnClient = YarnClient.createYarnClient();
        yarnClient.init(conf);
        yarnClient.start();
        return yarnClient;
    }
}
